﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model4D
{
    /// <summary>
    /// Класс описывающий многомерный мерный вектор.
    /// </summary>
    class Vector
    {
        double[] _X = null;

        public Vector(double[] X)
        {
            _X = X;
        }

        public Vector(int size)
        {
            _X = new double[size];
            Array.Clear(_X, 0, size);
        }

        public double[] X
        {
            get { return _X; }
            set { _X = value; }
        }

        public int Size => _X != null ? _X.Length : 0;

        public double this[int index]
        {
            get { return _X[index]; }
            set { _X[index] = value; }
        }

        /// <summary>
        /// Оператор сложения векторов.
        /// </summary>
        /// <param name="vector1">Вектор 1.</param>
        /// <param name="vector2">Вектор 2.</param>
        /// <returns>Вектор результат.</returns>
        static public Vector operator +(Vector vector1, Vector vector2)
        {
            if (vector1 == null)
                throw new NullReferenceException("vector1 is equal to null");

            if (vector2 == null)
                throw new NullReferenceException("vector2 is equal to null");

            if (vector1.Size != vector2.Size)
                throw new Exception("Size of vector1 is not equal to size of vector2.");

            Vector result = new Vector(vector1.Size);

            for (int i = 0; i < result.Size; i++)
            {
                result[i] = vector1[i] + vector2[i];
            }

            return result;
        }
    }
}
